﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace TankDemo
{
    class PublicClass
    {


        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="filename"></param>
        public static Dictionary<string, Object> updateImg(string filename)
        {

            System.Net.WebClient myWebClient = new System.Net.WebClient();
            byte[] responseArray = myWebClient.UploadFile("http://39.97.172.34:8080/upload", "POST", filename);
            string jsonstr = Encoding.ASCII.GetString(responseArray);

            Dictionary<string, Object> dict = new Dictionary<string, Object>();
            JsonReader reader = new JsonTextReader(new StringReader(jsonstr));

            string val = "";
            while (reader.Read())
            {

                if (reader.Value != null)
                {

                    if (reader.TokenType == JsonToken.PropertyName)
                    {
                        val = reader.Value.ToString();

                        Console.WriteLine("Token: {0}, Value: {1}", reader.TokenType, reader.Value);
                    }
                    else if (reader.TokenType == JsonToken.String)
                    {
                        if (val != "")
                        {
                            dict.Add(val, reader.Value);
                        }
                    }
                    else
                    {
                        val = "";
                    }
                }



            }
            return dict;

        }

    }
   
}
